<?php
	/**
	* Products Module Datatype
	* @author trungdt
	* @since Sep 27, 2011
	* 
	*/
	class bannermedia{	
		/**
		* return default country object
		* 
		*/
		public static function bannermedia_default_object(){
			$obj=null;
			$obj->title="";
			$obj->file_id=-1;
			$obj->item_content="";
			$obj->item_type=-1;
			return $obj;
		}

		function bannermedia_form($object) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			exponent_forms_initialize();
			$form = new form();
			if (!isset($object->id)) {
				$object = bannermedia::bannermedia_default_object();
			} else {
				$form->meta('id',$object->id);
			}
            $form->register('title','Title',new textcontrol($object->title));
			$item_type=array(0=>"Text",1=>"Image",2=>"Video Embed",3=>'My Video');
            $form->register('item_type','Item Type',new dropdowncontrol($object->$item_type,$item_type,false));
			$form->register('item_content','Item Content (Embed Code)',new texteditorcontrol($object->item_content));
			$form->register('file_id','Path (Only for type image or my video)', new ajax_select_file("file_id",0,$object->file_id,true));
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}
		function bannermedia_update($values,$object) {
			$object->title = $values['title'];
			$object->item_type = $values['item_type'];
			$object->item_content = $values['item_content'];
			// Path
			$object->file_id = $values['file_id'];
			
			return $object;
		}
		
		/**
		* return default state object
		* 
		*/
		public static function state_default_object(){
			$obj=null;
			$obj->name="";
			$obj->seo_name="";
			$obj->locale="";
			$obj->country_id = 0;
			return $obj;
		}
		
		function state_form($object, $country) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			exponent_forms_initialize();
			$form = new form();
			if (!isset($object->id)) {
				$object = geolocationmodule_country::state_default_object();
			} else {
				$form->meta('id',$object->id);
			}
			global $db;
			
			$countries=$db->selectDropdown('geolocationmodule_country','name',"location_data = '{$country->location_data}'");
			
			$form->register('name','State Name',new textcontrol($object->name));
			$form->register('seo_name','Seo Name',new textcontrol($object->seo_name));
			$form->register('locale','Locale',new textcontrol($object->locale));    
			$form->register('country_id','Country',new dropdowncontrol($object->country_id,$countries,false));
			
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}
		
		function state_update($values,$object) {
			$object->country_id = $values['country_id'];
			$object->name = $values['name'];
			$object->locale = $values['locale'];
			
			$object->seo_name = $values['seo_name'];
			if (trim($object->seo_name) == "")
				$object->seo_name = _to_vietnamese_with_nomark($values['name']);
			else
				$object->seo_name = _to_vietnamese_with_nomark($values['seo_name']);
			
			if (isset($object->id))
				$object->seo_name = _ab_check_seoname("geolocationmodule_country",$object->seo_name,$object->id);
			else
				$object->seo_name = _ab_check_seoname("geolocationmodule_country",$object->seo_name);
				
			return $object;
		}
		
		public static function city_default_object(){
			$obj=null;
			$obj->name="";
			$obj->seo_name="";
			$obj->locale="";
			$obj->state_id = 0;
			return $obj;
		}
		
		function city_form($object, $state) {
			if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
			global $db;
			exponent_forms_initialize();
			$form = new form();
			if (!isset($object->id)) {
				$object = geolocationmodule_country::city_default_object();
			} else {
				$form->meta('id',$object->id);
			}
			
			$state=$db->selectDropdown('geolocationmodule_state','name',"location_data = '{$state->location_data}' AND country_id = {$state->country_id}");
			
			$form->register('name','City Name',new textcontrol($object->name));
			$form->register('seo_name','Seo Name',new textcontrol($object->seo_name));
			$form->register('locale','Locale',new textcontrol(
$object->locale));

			$form->register('state_id','State',new dropdowncontrol($object->state_id,$state));
			//$form->register('country_id','Name Country',new co)
			$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
			return $form;
		}

		function city_update($values,$object) {
			$object->state_id = $values['state_id'];
			$object->name = $values['name'];
			$object->locale = $values['locale'];
			
			$object->state_id = intval($values['state_id']);
			
			$object->seo_name = $values['seo_name'];
			if (trim($object->seo_name) == "")
				$object->seo_name = _to_vietnamese_with_nomark($values['name']);
			else
				$object->seo_name = _to_vietnamese_with_nomark($values['seo_name']);
			
			if (isset($object->id))
				$object->seo_name = _ab_check_seoname("geolocationmodule_country",$object->seo_name,$object->id);
			else
				$object->seo_name = _ab_check_seoname("geolocationmodule_country",$object->seo_name);

			return $object;
		}

		
	}
?>
